BINNAME1=server1
BINNAME2=server2
BINNAME3=server3
RELEASE=-s -w

GOOS=$(shell uname -s | tr [A-Z] [a-z])
GOARGS=GOARCH=amd64 CGO_ENABLED=1
ifeq ($(GOOS),windows)
	GOBIN=go
	UPXBIN=
else
	ifeq ($(GOOS),darwin)
		GOBIN=/usr/local/bin/go
		UPXBIN=/usr/local/bin/upx
	else
		GOBIN=/usr/bin/go
		UPXBIN=/usr/bin/upx
	endif
endif
GOBUILD=$(GOARGS) $(GOBIN) build -ldflags="$(RELEASE)"

.PHONY: all build clean upx

all: clean build
build:
	@echo "Compile $(BINNAME1) $(BINNAME2) ..."
	GOOS=$(GOOS) $(GOBUILD) -o $(BINNAME1) ./cmd/gnet
	GOOS=$(GOOS) $(GOBUILD) -o $(BINNAME2) ./cmd/go_net
	@echo "Build success."
clean:
	rm -f $(BINNAME1) $(BINNAME2)
	@echo "Clean all."
upx: clean build
	$(UPXBIN) $(BINNAME1) $(BINNAME2)
